package com.example.firstdemo.ui.screens.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import com.example.firstdemo.ui.theme.AppTheme
import com.example.firstdemo.ui.theme.FontSize
import com.example.firstdemo.ui.theme.Space
import com.example.firstdemo.ui.theme.eColors

@Composable
fun MessageBox(
    title: String = "消息通知框",
    info: String = "这是一个完全自定义的对话框，内边距可以随意调整。",
    confirmText: String = "确定",
    onDismiss: () -> Unit = {},
    onConfirm: () -> Unit = {}
) {
    Dialog(onDismissRequest = onDismiss) {
        Card(
            modifier = Modifier
                .fillMaxWidth()
                .wrapContentHeight(),
            shape = RoundedCornerShape(16.dp),
        ) {
            Column(modifier = Modifier.padding(Space.medium)) {
                Text(
                    text = title,
                    color = MaterialTheme.eColors.text.regular,
                    fontSize = FontSize.large
                )
                Spacer(modifier = Modifier.height(Space.small))
                Text(
                    text = info,
                    color = MaterialTheme.eColors.text.regular,
                )
                Spacer(modifier = Modifier.height(Space.medium))
                Row(horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth()) {
                    TextButton(onClick = onConfirm) { Text(confirmText) }
                }
            }
        }
    }
}

@Preview(
    showBackground = true,
    showSystemUi = false
)
@Composable
fun MessageBoxPreview() {
    AppTheme() {
        MessageBox()
    }
}